package com.wf.atm.pojo;

import lombok.Getter;
import lombok.Setter;
import com.wf.atm.exception.BalanceNotEnoughException;

import java.io.Serializable;

/**
 * 信用账户
 *
 * @author mpk
 * @since 2024/6/3 18:13:30
 */

@Getter
public class CreditAccount extends Account implements Serializable {

    private static final long serialVersionUID = 3491859311276808410L;
    @Setter
    private double ceiling;



    public CreditAccount(Long id, String password, String name, String personId,String address, String email) {
        super(id, password, name, personId, address,email);

    }

    public CreditAccount() {

    }

    /**
     * @param money 取款金额
     * @return 账户
     */
    @Override
    public Account withdraw(double money) throws BalanceNotEnoughException {


        System.out.println("取款金额：" + money);
        if ((this.getBalance() + ceiling > money)) {

            this.setBalance(this.getBalance() - money);

        } else {
            throw new BalanceNotEnoughException("本金+信用额度超出取款金额, 余额：" + this.getBalance());
        }

        return this;


    }




    @Override
    public String toString() {
        return "CreditAccount{" + super.toString() + "," +
                "ceiling=" + ceiling +
                '}';
    }
}
